package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Scanner;

public class CheckinClient extends Client {
	private Service service;
	public CheckinClient(Service s) {
		super(s);
	}
	
	public String checkIn(int num) {
		String input = null;
		try {
			Service thisServer = getServer();
			Socket socket = new Socket(thisServer.getIpAddress(), thisServer.getPort());
			PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
			out.println(num);
			out.flush();
			BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		    input = in.readLine();
			System.out.println(input);
			out.close();
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return input;
	}


	public void run() {
			System.out.println("Service Discovered: " + service);
			System.out.println("Please enter your passenger registration number.");
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String response;
            try {
	            response = br.readLine();
	            int arg = Integer.parseInt(response);
	            checkIn(arg);
            } catch (IOException e) {
	            e.printStackTrace();
            }
	}

}
